package GreedyAlgorithmPackage;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @author Lzm
 * @version 1.0
 */
public class findContentChildren_ {
@Test
public void findContentChildren(){
  int[] g = new int[]{10,9,8,7};
  int[] s = new int[]{5,6,7,8};
  System.out.println(findContentChildren(g, s));
}
  public int findContentChildren(int[] g, int[] s) {
    int result  = 0;
    if (g.length == 0 || s.length == 0){
      return result;
    }
    Arrays.sort(g);
    Arrays.sort(s);
    int child = 0 ;
    int cookie = 0;
    for(child = 0 , cookie = 0 ; child < g.length && cookie < s.length;){
      if (g[child] <= s[cookie]){
        result ++;
        child ++;
        cookie ++;
        continue;
      }
      else{
        cookie ++;
      }
    }
    return result;
  }
}
